<extend name="Layout:ly1"/>

<block name="head">
    <style>
        #user_edit{
            margin-top: 10px;
        }
    </style>

    <script>
        //获取是否有新问题
        var text;
        var timerID;
        function ajaxGetNotify(){
            $.ajax({
                type:'get',
                url : '{:U("Admin/Ask/getAskStatus")}',
                dataType : 'json',
                success  : function(data) {
                    if(data > 0){
                        text = "您有【新消息】，请注意查收~";
                        newtext();
                    }else{
                        clearTimeout(timerID);
                        document.title = '中国农药第一网 - 农医问药 - 后台管理系统';
                    }
                },
                error : function() {}
            })
        }

        //标题滚动定时器
        function newtext() {
            clearTimeout(timerID)
            document.title=text.substring(1,text.length)+text.substring(0,1)
            text=document.title.substring(0,text.length)
            timerID = setTimeout("newtext()", 100)
        }

        setInterval("ajaxGetNotify()", parseInt(8) * 1000);

        $(document).ready(function () {
            /* var Table = $('table');
              var DataTable = Table.DataTable({
                  language: dataTables_zh_CN,
                  pageLength: 10,
                  aaSorting: [
                      [0,"desc"]
                  ]
              });
              */
            //添加

            $('#add_question').click(function(){
                layer.open({
                    type: 2,
                    title: '添加提问',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '580px'],
                    content: '{:U("Admin/Ask/question_add")}'
                });
            })

            //查看信息
            $('body').delegate('table tr td .view','click',function(){
                var url = $(this).parents('tr').data('view');
                layer.open({
                    type: 2,
                    title: '查看提问',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['60%', '80%'],
                    content: url
                });
            })

            //回复新增
            $('body').delegate('table tr td .reply-ask','click',function(){
                var url = $(this).parents('tr').data('reply-ask');
                layer.open({
                    type: 2,
                    title: '回复问答',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '530px'],
                    content: url
                });
            })

            //回复列表
            $('body').delegate('table tr td .reply-list','click',function(){
                var url = $(this).parents('tr').data('reply-list');
                layer.open({
                    type: 2,
                    title: '回复列表',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['60%', '80%'],
                    content: url
                });
            })

            //编辑信息
            $('body').delegate('table tr td .edit','click',function(){
                    var url = $(this).parents('tr').data('edit');
                    layer.open({
                        type: 2,
                        title: '编辑提问',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['50%', '570px'],
                        content: url
                    });
            })


            //删除信息
            $('body').delegate('table tr td .delete','click',function(){
                var id = $(this).parents('tr').data('id');
                layer.confirm('你确定要删除吗？', {
                    btn: ['确定','取消'], //按钮
                    shade: [0.4, '#393D49'] //显示遮罩
                }, function(){
                    $.get("{:U('Admin/Ask/question_delete')}",{"id": id},function(msg){
                        if(msg == 1){
                            layer.msg("删除成功，1秒后自动关闭~~",{ico:1,time:1000},function(){
                                $('table tr#id_'+id).remove();
                            })
                        }else if(msg == 2){
                            layer.msg("参数异常，1秒后自动关闭~~",{ico:1,time:1000});
                        }else{
                            layer.msg("删除失败，1秒后自动关闭~~",{ico:1,time:1000});
                        }
                    })
                });
            })
        });
    </script>

</block>

<block name="body">
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">提问管理</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        提问列表
                        <span class="pull-right"><a id="add_question">添加提问</a></span>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
					<div class="row">
					    <form   action="__URL__/question"  method="post">
						<div class="col-sm-6">
						<div class="dataTables_filter" >
						<label>搜索:<input  class="form-control input-sm"     type="text" name="mobile"  value="{$mobile|default=''}"   placeholder="请输入手机号或问题" ></label>
						  <input  type="submit" name="submit" style="margin-left:50px;" value="提交" />	
						</div>
						</div>
						</form>
						</div>
					
                        <div class="dataTable_wrapper">
                            <table class="table table-bordered table-hover table-responsive">
                                <thead>
                                <tr>
                                    <th>问题ID</th>
                                    <th>用户名</th>
                                    <th>问题内容</th>
                                    <th>发问时间</th>
                                    <th>问题分类</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                               <foreach name="question_list" item="v">
                                <tr id="id_{$v.id}" data-id="{$v.id}" data-reply-list="{:U('Admin/Ask/question_answer',['id'=>$v['id']])}" data-reply-ask="{:U('Admin/Ask/question_answer_add',['id'=>$v['id']])}" data-edit="{:U('Admin/Ask/question_edit',['id'=>$v['id'],'nickname'=>$v['nickname'],'content'=>$v['content'],'addtime'=>$v['addtime'],'cat_name'=>$v['cat_name']])}" data-view="{:U('Admin/Ask/question_view',['id'=>$v['id'],'nickname'=>$v['nickname'],'content'=>$v['content'],'addtime'=>$v['addtime'],'cat_name'=>$v['cat_name']])}" data-delete="{:U('Admin/Ask/question_delete',['id'=>$v['id']])}">
                                    <td width="6%">{$v.id }</td>
									
                                    <td width="10%">{$v.name}</td>
                                    <td width="28%">{$v.content}</td>
                                    <td width="10%">{$v.addtime}</td>
                                    <td width="8%">{$v.cat_name}</td>
                                    <td width="27%" align="center">
                                        <a class="btn btn-primary admin_user view">查看</a>

                                        <if condition="$v.answer_number gt 0">
                                            <a class="btn btn-success admin_user reply-list">回复列表({$v.answer_number})</a>
                                            <else />

                                            <a class="btn btn-danger admin_user reply-list">回复列表( 无 )</a>
                                        </if>

                                        <a class="btn btn-primary admin_user reply-ask">回复问题</a>
                                        <a class="btn btn-warning admin_user edit">编辑</a>
                                        <a class="btn btn-danger admin_user delete">删除</a>
                                    </td>
                                </tr>
                               </foreach>
							   	<tr>   <td  colspan="6"> {$page} </td> </tr>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
    </div>
    <!-- /#page-wrapper -->
</block>